﻿
using HoneyCms.Models;
using HoneyCms.Core.Data;
namespace HoneyCms.Services {
    public class PostService
    {
        private readonly AppDbContext _db;
        public PostService(AppDbContext db) => _db = db;

        public List<Post> GetAllPosts() => _db.Posts.ToList();
        public Post GetPost(int id)
        {
            return _db.Posts.FirstOrDefault(p => p.Id == id);
        }

        public void AddPost(Post post)
        {
            _db.Posts.Add(post);
            _db.SaveChanges();
        }
    }
}
